package com.dotflat.photoAlbum.controller;

import com.dotflat.photoAlbum.service.PhotoService;
import com.starinside.wp.components.MemVerificationCache;
import com.starinside.wp.domain.WxUser;
import com.starinside.wp.foundation.model.StatusResponse;
import com.starinside.wp.foundation.query.base.PagerQuery;
import com.starinside.wp.foundation.vo.BindedBabyVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import static com.starinside.wp.foundation.constant.RequestConstant.TICKET;


@RestController
@RequestMapping("/web/photo_album")
@Slf4j
@Api(tags = "班级相册 - ")
public class WebPhotoAlbumController {

    @Autowired
    private PhotoService photoService;

    @Autowired
    private MemVerificationCache cache;


    @ApiOperation(value = "获取相册下的照片，添加时间倒序")
    @GetMapping("/photos")
    public StatusResponse getPhotos(HttpServletRequest req, HttpServletResponse resp,
                                    @RequestHeader(TICKET) String ticket, PagerQuery pagerQuery ){

        WxUser loginUser = (WxUser) req.getSession().getAttribute("loginUser");
        BindedBabyVO defaultBaby = loginUser.getDefaultBaby();

        return StatusResponse.success(photoService.list(defaultBaby.getAreaId(), defaultBaby.getId(), pagerQuery));
    }
}
